/**
 * @생성일 : 2011. 9. 14.
 * @package : com.luffy.jsonp.view
 * 
 *
 */
package com.luffy.jsonp.view;

import java.io.Writer;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.codehaus.jackson.JsonEncoding;
import org.codehaus.jackson.map.ObjectMapper;
import org.springframework.web.servlet.view.json.MappingJacksonJsonView;

/**
 * <pre>
 * 역할적기.
 * </pre>
 * @작성자 : Administrator
 * @작성일 : 2011. 9. 14.
 * @package : com.luffy.jsonp.view
 *
 */
public class JSONPView extends MappingJacksonJsonView {
	private ObjectMapper objectMapper = new ObjectMapper();

	@Override
	protected void renderMergedOutputModel(Map<String, Object> model, HttpServletRequest request,
		HttpServletResponse response) throws Exception {

		Object value = filterModel(model);

		String callback = request.getParameter("callback");
		String json = objectMapper.writeValueAsString(value);

		Writer out = response.getWriter();
		out.append(callback).append("(").append(json).append(")");
		out.flush();
	}
}